package il.technion.cs236369.webserver;

import java.net.Socket;
import java.util.HashMap;
import org.apache.http.HttpRequest;
import org.apache.http.impl.DefaultHttpServerConnection;

/**
 * A class which holds connection parameters and request details in order to allow the request handler 
 * future treatment of the request open by the socket handlers
 *
 */
public class ExtendedHttpRequest{

	//This map holds and parameters supplied by the user, in the case a parameter is inserted twice
	//the last version holds
	private HashMap<String,String> paramters = new HashMap<String,String>();
	private String path = null;
	private DefaultHttpServerConnection serverConn = null;
	private HttpRequest httpRequest = null;
	private String type = null;
	
	/** the constructor receives all the connection details (parameters should be added later)
	 * @param Socket
	 * @param ServerConn
	 * @param HttpRequest
	 */
	public ExtendedHttpRequest(Socket Socket, DefaultHttpServerConnection ServerConn,HttpRequest HttpRequest){
		socket = Socket;
		serverConn = ServerConn;
		httpRequest = HttpRequest;
	}
	
	//connection attributes
	public DefaultHttpServerConnection getServerConn() {
		return serverConn;
	}

	public void setServerConn(DefaultHttpServerConnection serverConn) {
		this.serverConn = serverConn;
	}

	public HttpRequest getHttpRequest() {
		return httpRequest;
	}

	public void setHttpRequest(HttpRequest httpRequest) {
		this.httpRequest = httpRequest;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Socket getSocket() {
		return socket;
	}

	public void setSocket(Socket socket) {
		this.socket = socket;
	}

	private Socket socket;
	
	public void setParameter(String field, String value) {
		paramters.put(field, value);
	}
	
	/**
	 * @return a clone of this request parameter map 
	 */
	public HashMap<String,String> getParameters() {
		@SuppressWarnings("unchecked")
		HashMap<String, String> copy = (HashMap<String, String>) paramters.clone();
		return copy;
	}

	public void setTypeToPostResponse() {
		type = "POST";
	}

	public void setTypeToGetResponse() {
		type = "GET";
	}
	
	public String getType() {
		return type;
	}
	
}
